﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Model
{
    [Table("sys_number_rule")] // 绑定数据库表名
    public class NumberingRule
    {
        /// <summary>
        /// 规则ID，主键，自增
        /// </summary>
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Column("rule_id")] // 映射数据库列 rule_id
        public long RuleId { get; set; }

        /// <summary>
        /// 目标表单
        /// </summary>
        [Required]
        [StringLength(20)]
        [Column("target_form")] // 映射数据库列 target_form（关键！）
        public string TargetForm { get; set; }  // 注意：实体类属性是 TargetForm（正确拼写）

        /// <summary>
        /// 编号前缀
        /// </summary>
        [Required]
        [StringLength(10)]
        [Column("number_prefix")]
        public string NumberPrefix { get; set; }

        /// <summary>
        /// 时间规则
        /// </summary>
        [Required]
        [StringLength(50)]
        [Column("time_rule")]
        public string TimeRule { get; set; }

        /// <summary>
        /// 流水号位数
        /// </summary>
        [Required]
        [Column("serial_number_digit")]
        public string SerialNumberDigit { get; set; }

        /// <summary>
        /// 步长
        /// </summary>
        [Required]
        [Column("step")]
        public int Step { get; set; }

        /// <summary>
        /// 编号生成规则
        /// </summary>
        [Required]
        [StringLength(50)]
        [Column("number_generation_rule")]
        public string NumberGenerationRule { get; set; }

        /// <summary>
        /// 当前最大值（实体类中是 MaxValue，对应数据库列 max_value）
        /// </summary>
        [Required]
        [Column("max_value")] // 映射数据库列 max_value
        public int MaxValue { get; set; } = 0;

        /// <summary>
        /// 最后一次更新时间
        /// </summary>
        [Required]
        [Column("last_update_time")]
        public DateTime LastUpdateTime { get; set; } = DateTime.Now;

        /// <summary>
        /// 创建人
        /// </summary>
        [Required]
        [StringLength(20)]
        [Column("create_by")]
        public string CreateBy { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [Required]
        [Column("create_time")]
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 是否删除
        /// </summary>
        [Required]
        [Column("is_delete")]
        public string IsDelete { get; set; }

        /// <summary>
        /// 更新人
        /// </summary>
        [Required]
        [StringLength(20)]
        [Column("update_by")]
        public string UpdateBy { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        [Required]
        [Column("update_time")]
        public DateTime UpdateTime { get; set; }
    }
}